/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Copyright (C) 2011-2025 OpenFOAM Foundation
     \\/     M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

Class
    Foam::pointMVCWeight

Description
    Container to calculate weights for interpolating directly from vertices
    of cell using Mean Value Coordinates. Based on VTK's
    vtkMeanValueCoordinatesInterpolator.

    Reference:
    \verbatim
        Langer, T., Belyaev, A., & Seidel, H. P. (2006, June).
        Spherical barycentric coordinates.
        In Symposium on Geometry Processing (pp. 81-88).
    \endverbatim

SourceFiles
    pointMVCWeightI.H
    pointMVCWeight.C

\*---------------------------------------------------------------------------*/

#ifndef pointMVCWeight_H
#define pointMVCWeight_H

#include "point.H"
#include "volFieldsFwd.H"
#include "pointFieldsFwd.H"
#include "scalarField.H"
#include "vectorField.H"
#include "Map.H"
#include "DynamicList.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam
{

class face;
class polyMesh;
class pointMesh;

/*---------------------------------------------------------------------------*\
                       Class pointMVCWeight Declaration
\*---------------------------------------------------------------------------*/

class pointMVCWeight
{
protected:

    // Protected data

        //- Cell index
        const label cellIndex_;

        //- Weights applied to cell vertices
        scalarField weights_;


    // Protected Member Functions

        //- Calculate weights from single face's vertices only
        void calcWeights
        (
            const Map<label>& toLocal,
            const face& f,
            const DynamicList<point>& u,
            const scalarField& dist,
            scalarField& weights
        ) const;

        //- Calculate weights from all cell's vertices
        void calcWeights
        (
            const polyMesh& mesh,
            const labelList& toGlobal,
            const Map<label>& toLocal,
            const vector& position,
            const vectorField& uVec,
            const scalarField& dist,
            scalarField& weights
        ) const;


public:

    //- Type information
    ClassName("pointMVCWeight");


    // Static Member Data

        //- Tolerance used in calculating barycentric co-ordinates
        static scalar tol;


    // Constructors

        //- Construct from components
        pointMVCWeight
        (
            const polyMesh& mesh,
            const vector& position,
            const label celli,
            const label facei = -1
        );


    // Member Functions

        //- Cell index
        inline label cell() const
        {
            return cellIndex_;
        }

        //- Interpolation weights (in order of cellPoints)
        inline const scalarField& weights() const
        {
            return weights_;
        }

        //- Interpolate field
        template<class Type>
        inline Type interpolate
        (
            const PointField<Type>& psip
        ) const;
};


// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#include "pointMVCWeightI.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //
